package pl.shenlon.poker.cards;

import java.util.Collections;

public class CardUtils {

	public static Hand joinHands(Hand... hands) {
		int size = 0;
		for (Hand hand : hands) {
			size += hand.getCardsCount();
		}
		Card[] cards = new Card[size];
		int pos = 0;
		for (Hand hand : hands) {
			for (Card card : hand.getCards()) {
				if (card.isFaceUp()) {
					cards[pos] = card;
					pos++;
				}
			}
		}
		cards = java.util.Arrays.copyOf(cards, pos);
		java.util.Arrays.sort(cards, Collections.reverseOrder());
		return new Hand(cards);
	}

	public static Hand joinHands(Hand player, Hand table) {
		int size = player.getCardsCount() + table.getCardsCount();
		Card[] cards = new Card[size];
		int pos = 0;
		for (Card card : player.getCards()) {
			cards[pos++] = card;
		}
		for (Card card : table.getCards()) {
			if (card.isFaceUp()) {
				cards[pos++] = card;

			}
		}
		cards = java.util.Arrays.copyOf(cards, pos);
		java.util.Arrays.sort(cards, Collections.reverseOrder());
		return new Hand(cards);
	}
}